package chapter10Daemon;

/**
 * 守护线程
 * Created by LinGer on 2019/6/19
 */
public class DaemonTest extends Thread{

    public DaemonTest(String name){
        super(name);
    }

    @Override
    public void run() {
        try {
            for (int i = 0; i < 5; i++) {
                Thread.sleep(300);
                System.out.println(this.getName() + " is daemon? " + this.isDaemon() + " ,loop " + i);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName() + " is daemon? " + Thread.currentThread().isDaemon());

        Thread t1 = new NotDaemonTest("t1");
        Thread t2 = new DaemonTest("t2");
        //设置t2位守护线程
        t2.setDaemon(true);

        t1.start();
        t2.start();
    }
}
